// pages/recruit/recruit.js
const app = getApp();
const utils = require('../../utils/util.js');
const post = utils.post;
const getCurrentPageUrlWithArgs = utils.getCurrentPageUrlWithArgs;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    z_uid: '',
    m_uid: '',
    list: [],
    src: '',
    src_result: '',
    ifName: false,
    copywriting: '',
    weapp_status: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;

    wx.showLoading({
      mask: true,
      success: (result) => {
      }
    });

    let uid = wx.getStorageSync('z_uid');
    if (uid) {
      let p = {
        m: 'invite',
        uid: uid
      }
      post(p).then(res => {
        //console.log(res)
        that.setData({
          list: res,
          src_result: res.result,
          copywriting: res.copywriting
        })

        wx.hideLoading();
      })
    }

    let p0 = {
      m: 'weapp_status',
      v: 3
    };
    post(p0).then(res => {
      that.setData({
        weapp_status: res.status
      });
    });
  },

  ewmst: function () {
    let that = this;
    wx.setClipboardData({
      data: that.data.copywriting,
      success: function () {
        wx.hideToast();

        wx.showLoading({
          title: "加载中",
          mask: true,
          success: (result) => {
            that.setData({
              ifName: true,
              src: that.data.src_result
            });

            //wx.hideLoading();
          }
        });
      }
    });
    
    // console.log(that.data.copywriting)
  },
  ImgToPhotosAlbumTap: function () {
    let that = this;
    // console.log(that.data.src)
    wx.downloadFile({
      url: that.data.src_result, //仅为示例，并非真实的资源
      success: function (res) {
        wx.saveImageToPhotosAlbum({
          filePath: res.tempFilePath,
          success: function () {
            wx.showToast({
              title: '图片保存成功',
              icon: 'success',
              duration: 2000
            })
          }
        })
        if (res.statusCode === 200) {
          wx.playVoice({
            filePath: res.tempFilePath
          })
        }
      }
    });

    that.setData({
      ifName: false,
      src: ''
    });

  },

  closehb() {
    let that = this;
    that.setData({
      ifName: false,
      src: ''
    });
  },

  imageLoad: function (ev) {
     //console.log(ev)
    if (ev.detail.height > 0 && ev.detail.width > 0) {
      wx.hideLoading();
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  submitFormId(e) {
    let formId = e.detail.formId;
    let button = e.detail.target.dataset.name;
    var m_uid = wx.getStorageSync("m_uid");
    let page = getCurrentPageUrlWithArgs();
    let p = {
      m: 'colform',
      uid: m_uid,
      openid: wx.getStorageSync('weapp_openid'),
      formId: formId,
    }
    if (page && page.length > 0) {
      p.page = page;
    }
    if (button && button.length > 0) {
      p.button = button;
    }
    //console.log(p);
    post(p).then(res => {
    })
  }
})